package com.vslimit.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;

public class FuniApplicationContext implements ApplicationContextAware, ServletContextAware {
    private static ApplicationContext applicationContext;
    private static ServletContext servletContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        FuniApplicationContext.applicationContext = applicationContext;
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        FuniApplicationContext.servletContext = servletContext;
    }

    public static ServletContext getServletContext() {
        return servletContext;
    }

    public static Object getBean(String beanName) {
        Object object = null;
        if (applicationContext != null) {
            object = applicationContext.getBean(beanName);
        }
        return object;
    }
}